<%@ page import="br.com.rosena.model.bean.persistente.Persistente" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
 <%
    String nomeClasse = request.getParameter("nomeClasse") != null ? request.getParameter("nomeClasse") : "";

    Class.forName("org.postgresql.Driver").newInstance();
    Connection connection = DriverManager.getConnection(("jdbc:postgresql://db3081.pgsql81.laniway.com.br:5432/db3081"), "db3081a1", "appkyn3q");
    Statement stm = connection.createStatement();
    ResultSet crs = stm.executeQuery("select id from " + nomeClasse+"  ORDER BY ID ");

     Class.forName("org.postgresql.Driver").newInstance();
     Connection connection2 = DriverManager.getConnection(("jdbc:postgresql://pgsql.setic.ufsc.br:5432/sile"), "sile", "IeP2Cab1");
     connection2.setAutoCommit(true);

    try {
       rod(crs,nomeClasse,out,connection2);
       out.println("INCLUINDO");
    } catch (Exception ex) {
        ex.printStackTrace();
        out.print(ex.getMessage());
        rod(crs,nomeClasse,out,connection2);
        out.println("ERROROOOOOOOOOOOOO");
    }

    out.print("FINALIZADO COM SUCESSO PARABENS!");

%>
<%!
    public void rod(ResultSet crs, String nomeClasse,  JspWriter out,Connection connection2) throws Exception {
        String query = "";
        while (crs.next()) {
            Persistente objPrincipal = new Persistente(nomeClasse, crs.getLong("ID"));
            objPrincipal.getClasse().iniciarQueryCache(objPrincipal.getClasse(), objPrincipal);
            query = objPrincipal.getClasse().getSqlGravar().toString().replace("VALUES (", "VALUES ( " + crs.getLong("ID") + ", ").replace("(nomeClasse", "(ID, nomeClasse");
            query = query.replace("." + objPrincipal.getClasse().getNomeTabelaBancoDados(), objPrincipal.getClasse().getNomeTabelaBancoDados());
            Statement stm2 = connection2.createStatement();
            //stm2.execute(query);
            out.println(query);
            System.out.println("INSERT");
         }
    }
%>
<html>
    <head><title>Teste</title></head>
    <body>
    </body>
</html>

 